package com.wqr.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wqr.pojo.UserTypes;
import com.wqr.service.UserTypesService;

@Controller
public class UserTypesController {
	@Autowired
    public UserTypesService userTypesService;
	
	@RequestMapping("/addUserTypes")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int addUserTypes(@RequestBody //读取Request请求的body部分数据,再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上
			UserTypes userTypes) throws Exception {
		//IsLogin(session);
		int a = userTypesService.insertUserTypes(userTypes);
		return a;
		//return "redirect:/manageUserTypes.action";
	}
	//@RequestMapping(value="/deleteUserTypes/{userTypeId}",method=RequestMethod.GET)
	@RequestMapping("/deleteUserTypes")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int deleteUserTypes(@RequestBody //读取Request请求的body部分数据,再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上
			UserTypes userTypes) throws Exception {
		//@pathVariable //将 URL 中占位符参数绑定到控制器处理方法的入参中 URL 中的 {xxx} 占位符可以通过@PathVariable("xxx") 绑定到操作方法的入参中。
		//(userTypeId) Integer userTypeId) throws Exception {
		//IsLogin(session);
		int a = userTypesService.delectUserTypes(userTypes.getUserTypeId());
		return a;
	}
	@RequestMapping("/updateUserTypes")
	@ResponseBody
	public List<UserTypes> updateUserTypes(@RequestBody UserTypes userTypes) throws Exception {
		//IsLogin(session);
		List<UserTypes> itemList = userTypesService.selectUserTypes(userTypes);
		return itemList;
	}
	@RequestMapping("/saveUserTypes")
	@ResponseBody// 返回的数据不是html标签的页面，而是其他某种格式的数据时（如json、xml等）使用；
	public int saveUserTypes(@RequestBody UserTypes userTypes) throws Exception {
		//IsLogin(session);
		int a = userTypesService.updateUserTypes(userTypes);
		return a;
	}
	//LogintypeBean loginType = service.getLogintypeByLoginTypeId(loginTypeId);
	@RequestMapping("/searchUserTypes")
	@ResponseBody
	public List<UserTypes> searchUserTypes(@RequestBody UserTypes userTypes,Model model) throws Exception {
		if(userTypes.getUserTypeName() == ""){
			userTypes.setUserTypeName(null);
		}
		if(userTypes.getDescription() == ""){
			userTypes.setDescription(null);
		}
		List<UserTypes> itemList = userTypesService.selectUserTypes(userTypes);
	    return itemList;
	}
	@RequestMapping("/searchAllUserTypes")
	@ResponseBody
	public List<UserTypes> searchAllUserTypes() throws Exception {
		List<UserTypes> itemList = userTypesService.selectAll();
	    return itemList;
	}
	@RequestMapping("/manageUserTypes")
	public String userTypes(Model model) throws Exception {
		List<UserTypes> list = userTypesService.list();
		model.addAttribute("itemList", list);
	    return "manageLoginTypes"; 
	}
}
